
import org.junit.Before;
import org.junit.*;
import static org.junit.Assert.*;

public class TemperatureTest {

	private double temperatureMaxValue;

	@Before
	public void setUp() throws Exception {
		temperatureMaxValue = 10 * Math.exp(20);
	}

	@Test
	public void isValidTemperature_LegalCase() {

		// Eenvoudige test.

		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(200,
				Temperature.CELCIUS));
		assertEquals(true,
				Temperature.CELCIUS.isValidTemperature(200, Temperature.KELVIN));
		assertEquals(true, Temperature.KELVIN.isValidTemperature(200,
				Temperature.FAHRENHEIT));

		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(200,
				Temperature.FAHRENHEIT));
		assertEquals(true, Temperature.CELCIUS.isValidTemperature(200,
				Temperature.CELCIUS));
		assertEquals(true,
				Temperature.KELVIN.isValidTemperature(200, Temperature.KELVIN));

		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(200,
				Temperature.KELVIN));
		assertEquals(true, Temperature.CELCIUS.isValidTemperature(200,
				Temperature.FAHRENHEIT));
		assertEquals(true,
				Temperature.KELVIN.isValidTemperature(200, Temperature.CELCIUS));

		// Randgevallen

		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(
				temperatureMaxValue, Temperature.FAHRENHEIT));
		assertEquals(true, Temperature.CELCIUS.isValidTemperature(
				temperatureMaxValue, Temperature.FAHRENHEIT));
		assertEquals(true, Temperature.CELCIUS.isValidTemperature(
				Double.MIN_VALUE, Temperature.FAHRENHEIT));

		assertEquals(true, Temperature.CELCIUS.isValidTemperature(
				temperatureMaxValue, Temperature.KELVIN));
		assertEquals(true, Temperature.CELCIUS.isValidTemperature(
				Double.MIN_VALUE, Temperature.KELVIN));
		assertEquals(true, Temperature.KELVIN.isValidTemperature(
				temperatureMaxValue - 1, Temperature.CELCIUS));
		assertEquals(true, Temperature.KELVIN.isValidTemperature(
				temperatureMaxValue, Temperature.KELVIN));

		assertEquals(true,
				Temperature.CELCIUS.isValidTemperature(0, Temperature.KELVIN));
		assertEquals(true, Temperature.CELCIUS.isValidTemperature(0,
				Temperature.FAHRENHEIT));
		assertEquals(true,
				Temperature.CELCIUS.isValidTemperature(0, Temperature.CELCIUS));

		assertEquals(true,
				Temperature.KELVIN.isValidTemperature(0, Temperature.KELVIN));
		assertEquals(true, Temperature.KELVIN.isValidTemperature(0,
				Temperature.FAHRENHEIT));
		assertEquals(true,
				Temperature.KELVIN.isValidTemperature(0, Temperature.CELCIUS));

		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(0,
				Temperature.KELVIN));
		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(0,
				Temperature.FAHRENHEIT));
		assertEquals(true, Temperature.FAHRENHEIT.isValidTemperature(0,
				Temperature.CELCIUS));
	}

	@Test
	public void isValidTemperature_IllegalCase() {

		// Randgevallen
		assertEquals(false, Temperature.FAHRENHEIT.isValidTemperature(
				temperatureMaxValue + 1, Temperature.CELCIUS));
		assertEquals(false, Temperature.FAHRENHEIT.isValidTemperature(
				temperatureMaxValue, Temperature.CELCIUS));
		assertEquals(false, Temperature.FAHRENHEIT.isValidTemperature(
				Double.MIN_VALUE, Temperature.CELCIUS));

		assertEquals(false, Temperature.FAHRENHEIT.isValidTemperature(
				temperatureMaxValue * 9 / 5 + 32, Temperature.FAHRENHEIT));
		assertEquals(false, Temperature.FAHRENHEIT.isValidTemperature(
				Double.MIN_VALUE, Temperature.FAHRENHEIT));
		assertEquals(false, Temperature.CELCIUS.isValidTemperature(
				temperatureMaxValue * 9 / 5 + 32, Temperature.FAHRENHEIT));

		assertEquals(false, Temperature.CELCIUS.isValidTemperature(
				temperatureMaxValue + 273.15, Temperature.KELVIN));
		assertEquals(false, Temperature.CELCIUS.isValidTemperature(
				temperatureMaxValue, Temperature.CELCIUS));
		assertEquals(false, Temperature.CELCIUS.isValidTemperature(
				Double.MIN_VALUE, Temperature.CELCIUS));

		assertEquals(false, Temperature.KELVIN.isValidTemperature(
				temperatureMaxValue, Temperature.CELCIUS));
		assertEquals(false, Temperature.KELVIN.isValidTemperature(
				Double.MIN_VALUE, Temperature.CELCIUS));
		assertEquals(false, Temperature.KELVIN.isValidTemperature(
				temperatureMaxValue + 273.15, Temperature.KELVIN));
		assertEquals(false, Temperature.KELVIN.isValidTemperature(
				Double.MIN_VALUE, Temperature.KELVIN));
	}

	@Test
	public void converts_LegalCase() {
		
		assertEquals(212, (int) Temperature.CELCIUS.convertTo(100, Temperature.FAHRENHEIT));
		assertEquals(37, (int) Temperature.FAHRENHEIT.convertTo(100, Temperature.CELCIUS));
		
		assertEquals(273, (int) Temperature.CELCIUS.convertTo(0, Temperature.KELVIN));
		assertEquals(0, (int) Temperature.KELVIN.convertTo(273,Temperature.CELCIUS));
		
		assertEquals(310, (int) Temperature.FAHRENHEIT.convertTo(100,Temperature.KELVIN));
		assertEquals(98, (int) Temperature.KELVIN.convertTo(310,Temperature.FAHRENHEIT));
		
		assertEquals(-100, (int) Temperature.KELVIN.convertTo(-100,Temperature.KELVIN));
		assertEquals(273, (int) Temperature.FAHRENHEIT.convertTo(273,Temperature.FAHRENHEIT));
		assertEquals(100, (int) Temperature.CELCIUS.convertTo(100, Temperature.CELCIUS));
	}
}
